using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace FingerReader_demo
{
    public partial class ViewTmp : Form
    {
        public ViewTmp()
        {
            InitializeComponent();
        }
        public OleDbConnection conn = null;
        private OleDbDataAdapter adp = null;
        private OleDbCommandBuilder builder = null;
        private DataSet data_set = new DataSet();
        private void btn_select_all_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                dataGridView1[0, i].Value = true;          //全选
            }
        }

        private void btn_anti_select_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
                {
                    dataGridView1[0, i].Value = false;//反选
                }
                else
                    dataGridView1[0, i].Value = true;
            }
        }

        private void ViewTmp_Load(object sender, EventArgs e)
        {
            viewtmp();
        }

        private void viewtmp()
        {
            adp = new OleDbDataAdapter("select * from template", conn);
            builder = new OleDbCommandBuilder(adp);
            adp.Fill(data_set, "tmp");
            dataGridView1.DataSource = data_set.Tables["tmp"];
        }

        private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void btn_delete_Click(object sender, EventArgs e)
        {
            int count11 = dataGridView1.RowCount;
            for (int i = 0; i < count11; i++)
            {
                if (dataGridView1.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
                {
                    data_set.Tables["tmp"].Rows[i].Delete();
                    //adp.Update(data_set, "DevInfo");
                    i--;                    //注：此处删除了一行之后总行数也相应少了一行，故此有如下两语句
                    count11--;
                    adp.Update(data_set, "tmp");
                }

            }
        }
    }
}
